home *** CD-ROM | disk | FTP | other *** search
/ The Real Yellow Pages - Tampa Bay 2009 / The Real Yellow Pages - Tampa Bay 2009.iso / pc / intranet / unix / setup.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2008-02-21  |  7.4 KB  |  347 lines

  1. #!/bin/ksh
  2. umask 022
  3. PATH=$PATH:/usr/bin:/bin:/etc:/usr/sbin; export PATH
  4. ## Working directory
  5. WORKDIR=`dirname $0`
  6. ##
  7. ## BKSINST information
  8. ##
  9. ## Current ezlistings version
  10. CURVER="5.0.14"
  11. ## Optional upgrade version
  12. OPTVER=""
  13. ## Required upgrade version
  14. REQVER="5.0.14"
  15. ## Product version number
  16. VERSION=""
  17. ## Product name
  18. PRODUCT="The Real Yellow Pages"
  19.  
  20. ##
  21. ## Image directories for each book
  22. ##
  23. BOOKTOTAL=1
  24.  
  25. TAFDIR="taf08"
  26.  
  27. TAFNM="Tampa, FL"
  28.  
  29. TAFYR="${TAFNM} (Mar 2008/2009)"
  30.  
  31. TAF="${TAFYR}\n${TAFDIR}"
  32.  
  33. BOOKS_DIR="${WORKDIR}/../../books"
  34.  
  35. BEEP="\007"
  36.  
  37. ##
  38. ## Function used to build the _bksinst file and install each book
  39. ## that was selected.
  40. ##
  41. function BuildBksInst {
  42.     clear
  43.     BooksDir=${NewDir}/books
  44.     if [ ! -d ${BooksDir} ]; then
  45.         mkdir ${NewDir}/books
  46.     fi
  47.     BKSINST=${BooksDir}/_bksinst.eza
  48.     echo ${CURVER} > ${BKSINST}
  49.     echo ${OPTVER} >> ${BKSINST}
  50.     echo ${REQVER} >> ${BKSINST}
  51.     ## Beginning of tagged file
  52.     ## Two blank lines necessary for exe to read tagged file
  53.     echo "" >> ${BKSINST}
  54.     echo "" >> ${BKSINST}
  55.     if [ "${DEFAULTBOOKCODE}" != "" ]; then
  56.         echo "** DefaultBookCode **" >> ${BKSINST}
  57.         echo "${DEFAULTBOOKCODE}" >> ${BKSINST}
  58.     fi
  59.     if [ ${Url} != "" ]; then
  60.         echo "** URL **" >> ${BKSINST}
  61.         echo "${Url}/books" >> ${BKSINST}
  62.     fi
  63.     echo "** Name **" >> ${BKSINST}
  64.     echo ${PRODUCT} >> ${BKSINST}
  65.     echo "** Books **" >> ${BKSINST}
  66.     i=0
  67.     ## Loop through book array
  68.     ## Source directory for all Books is found one level above
  69.     while [ i -lt ${cnt} ]; do
  70.         case "${array[${i}]}"
  71.         in
  72.             1) echo ${TAF} >> ${BKSINST}
  73.                echo "Installing ${TAFYR} directory..."
  74.                cp -r ${BOOKS_DIR}/${TAFDIR} ${BooksDir}
  75.                ;;
  76.         esac
  77.         let "i = i + 1"
  78.     done
  79.     if [ ! -e ${BooksDir}/_bksinst.lic ]; then
  80.       echo  >> ${BooksDir}/_bksinst.lic
  81.     fi
  82.     for i in `find ${BooksDir} -name "xtr0*." -print | cut -f1 -d'.'`; do
  83.         mv ${i}. ${i} > /dev/null 2>&1
  84.     done
  85.     cp ${WORKDIR}/*.exe ${NewDir}
  86.     cp ${WORKDIR}/*.gif ${NewDir}
  87.     cp ${WORKDIR}/*.txt ${NewDir}
  88.     cp ${WORKDIR}/*.htm* ${NewDir}
  89.     cp ${WORKDIR}/*.cab ${NewDir}
  90.     echo "\n<tags><url>$url</url></tags>" >> ${NewDir}/client32.exe
  91.     if [ -d ${WORKDIR}/../../mac ]; then
  92.         if [ ! -d ${NewDir}/mac ]; then
  93.             mkdir ${NewDir}/mac
  94.         fi
  95.         chmod 755 ${NewDir}/macintro.htm
  96.         cp ${WORKDIR}/../../mac/*.* ${NewDir}/mac
  97.         ## START URL SUBSTITUTION
  98.         Url=`echo "${Url}" |sed 's/\//\\\\\//g'`
  99.         sed s/"<!-- \*\* WHITE PAGES URL \*\* -->"/"${Url}"/g  ${WORKDIR}/macintro.htm > ${NewDir}/macintro.htm
  100.         ## END OF URL SUBSTITUTION
  101.     fi
  102. }
  103.  
  104. ##
  105. ## Function used to display the product license.  The user must accept this
  106. ## to continue.
  107. ##
  108. function ShowLicense {
  109.     cat ${WORKDIR}/license.txt | more
  110.     echo "\nEnter \"Y\" to accept these terms and conditions ? (Y/N)\c "
  111.     read ans
  112. }
  113.  
  114. ##
  115. ## Function used to prompt for the installation path.
  116. ##
  117. function GetRootPath {
  118.     clear
  119.     echo "Please enter the full path to the ${PRODUCT} content directory."
  120.     echo "This install will copy all files to this directory."
  121.     echo
  122.     echo "Install path: \c"
  123.     read NewDir
  124. }
  125.  
  126. ##
  127. ## Function used to prompt for book selections.  The user may enter an
  128. ## individual number or a range of numbers.
  129. ##
  130. function GetBooks {
  131.     clear
  132.     echo "Enter the number of the book or books you wish to install. You"
  133.     echo "may comma separate each number or use a hyphen for consecutive"
  134.     echo "numbers".
  135.     echo
  136.     echo "Example: 1,3,5-8 would install books 1,3 and 5 through 8"
  137.     echo
  138.     echo "\t 1) ${TAFNM}"
  139.     echo
  140.     echo "Enter choices: \c"
  141.     read BookChoices
  142. }
  143.  
  144. ##
  145. ## Function used to prompt for the ezlistings URL.
  146. ##
  147. function GetUrl {
  148.     clear
  149.     echo "Enter the intranet URL which will point to ${PRODUCT} content"
  150.     echo "directory."
  151.     echo
  152.     echo "Example: http://www.server.com/~server"
  153.     echo
  154.     echo "\nEnter the URL used for ${PRODUCT}: \c"
  155.     read Url
  156.     Url=`echo ${Url} | sed "s/\/$//"`
  157.     url=${Url}
  158. }
  159.  
  160. ##
  161. ## Function used to enter book choices into an array.  A book choice is
  162. ## compared to what is in the array already.  If it is a duplicate entry
  163. ## it is ignored, otherwise it is added to the array
  164. ##
  165. function PutData {
  166.     if [ ${Data} -ge 1 -a ${Data} -le ${BOOKTOTAL} ]; then
  167.         i=0
  168.         ## Check each book entry to see if choice already exists
  169.         while [ i -lt ${cnt} ]; do
  170.             if [ "${array[${i}]}" = "${Data}" ]; then
  171.                 break;
  172.             fi
  173.             let "i = i + 1"
  174.         done
  175.         ## If choice did not exist add choice to array
  176.         if [ ${i} -eq ${cnt} ]; then
  177.             array[${cnt}]="${Data}"
  178.             let "cnt = cnt + 1"
  179.         fi
  180.     fi
  181. }
  182.  
  183. ##
  184. ## Function used to generate numbers for a range of book choces entered.
  185. ##
  186. function PutRangeData {
  187.     newData=`echo ${Data} | sed 's/-/ /g'`
  188.     ## Blank out delimeter and convert into command line entries
  189.     set -- ${newData}
  190.     j=$1
  191.     while [ $j -le $2 ]; do
  192.         Data=$j
  193.         PutData
  194.         let "j = j + 1"
  195.     done
  196. }
  197.  
  198. ##
  199. ## Function used to parse the book choice string.  The function uses the "set"
  200. ## command to simulate command line entries.  It then shifts through entry to
  201. ## it reaches the end.  If a - is found, the entry is assumed to be a range of
  202. ## numbers.  Any number outside of 1 - 9 will be ignored.
  203. ##
  204. function ParseCmd {
  205.     newline=`echo ${BookChoices} | sed 's/,/ /g'`
  206.     set -- ${newline}
  207.     while [ $# -gt 0 ]; do
  208.         Data=${1}
  209.         if [ "`echo ${Data} | grep "-"`" = "" ]; then
  210.             PutData
  211.         else
  212.             PutRangeData
  213.         fi
  214.         shift
  215.     done
  216. }
  217.  
  218. ##
  219. ## Function used to display install information.  This function is called
  220. ## just before installation begins.  Last chance to abort.
  221. ##
  222. function BeginInstall {
  223.     clear
  224.     echo "The following information will be used to install"
  225.     echo "${PRODUCT} Server."
  226.     echo
  227.     echo "Target directory:\t\t${NewDir}"
  228.     echo
  229.     echo "URL pointing to ${PRODUCT} data:\t${Url}"
  230.     echo
  231.     echo "Default book:\t\t\t${DEFAULTBOOK}"
  232.     echo
  233.     echo "Books to install:"
  234.     i=0
  235.     ## Loop through book array and display book choices by name
  236.     while [ i -lt ${cnt} ]; do
  237.         case "${array[${i}]}"
  238.         in
  239.             1) echo "\t${TAFYR}";;
  240.         esac
  241.         let "i = i + 1"
  242.     done
  243.     echo
  244.     echo "Do you want to continue with the install? (Y/N)\c"
  245.     read ans
  246. }
  247.  
  248. ##
  249. ## Function used to prompt the user for a default book
  250. ##
  251. function GetDefaultBook {
  252.     bookAns=1
  253.     if [ ${cnt} -gt 1 ]; then
  254.         while [ 1 ]; do
  255.             clear
  256.             i=0
  257.             j=0
  258.             echo "Select a default book to open when ${PRODUCT} application"
  259.             echo "is started by an end user."
  260.             echo
  261.             while [ i -lt ${cnt} ]; do
  262.                 let "j = j + 1"
  263.                 case "${array[${i}]}"
  264.                 in
  265.                     1) echo "${j}) ${TAFYR}";;
  266.                 esac
  267.                 let "i = i + 1"
  268.             done
  269.             echo
  270.             echo "Select a default book: (1 - ${cnt}) \c"
  271.             read bookAns
  272.             ## Make sure default choice is within range
  273.             if [ ${bookAns} -ge 1 -a ${bookAns} -le ${cnt} ]; then
  274.                 break
  275.             fi
  276.             echo ${BEEP}
  277.         done
  278.     fi
  279.     let "bookAns = bookAns - 1"
  280.     case "${array[${bookAns}]}"
  281.     in
  282.         1) DEFAULTBOOKCODE="taf";;
  283.     esac
  284.     case "${array[${bookAns}]}"
  285.     in
  286.         1) DEFAULTBOOK="${TAFNM}";;
  287.     esac
  288. }
  289.  
  290. ##
  291. ## Main
  292. ##
  293.  
  294. ## Global variables
  295. ##
  296. ## Answer to Yes or No question
  297. ans=""
  298. ## Set to a book array value
  299. Data=""
  300. ## Book choice array
  301. array=
  302. ## Number of books selected
  303. cnt=0
  304. ## Install directory
  305. NewDir=""
  306. ## Web server root path
  307. NewDir=""
  308. ## The product's root directory
  309. Url=""
  310. ## Default book choice
  311. DEFAULTBOOK=""
  312. DEFAULTBOOKCODE=""
  313.  
  314. clear
  315. ShowLicense
  316. clear
  317. if [ "${ans}" = "Y" -o "${ans}" = "y" ]; then
  318.     GetRootPath
  319.     GetUrl
  320.     while [ 1 ]; do
  321.         GetBooks
  322.         ParseCmd
  323.         if [ ${cnt} -eq 0 ]; then
  324.             echo
  325.             echo ${BEEP}
  326.             echo "No books were selected!  Do you want to make a selection? (Y/N) \c"
  327.             read ans
  328.             if [ "${ans}" = "Y" -o "${ans}" = "y" ]; then
  329.                 continue
  330.             fi
  331.         fi
  332.         break
  333.     done
  334.     #InstallPath
  335.     GetDefaultBook
  336.  
  337.     BeginInstall
  338.     if [ "${ans}" = "Y" -o "${ans}" = "y" ]; then
  339.         if [ ! -d ${NewDir} ]; then
  340.             mkdir -p ${NewDir}
  341.         fi
  342.         BuildBksInst
  343.     fi
  344. fi
  345. exit 0
  346.  
  347.